import { createSSRApp } from "vue";
import App from "./App.vue";
import { setting } from "@/util";
export function createApp() {
  const app = createSSRApp(App);
  app.use({
    install(app) {
      app.mixin({
        async onLoad(p) {
          let gid = uni.getStorageSync("gid");
          if (p && p.gid) { gid = p.gid; }
          if (!gid) { gid = "0"; }
          const cs = getCurrentPages(), c = cs[cs.length - 1];
          if (parseInt(await setting("distribution")) && c?.route === "pages/index") {
            uni.setNavigationBarTitle({ title: `正在查询门店信息` });
            const r = await gd.group.getById(gid);
            if (r) {
              uni.setNavigationBarTitle({ title: `门店:${r.name}` });
              uni.setNavigationBarColor({ frontColor: "#ffffff", backgroundColor: "#dd524d" });
              uni.setStorageSync("gid", gid);
              if (!api.me.pid && `${gid}` !== "0") {
                api.me.pid = r.create;
                await request({ pid: r.create }, "/user/setPid");
              }
            }
          }
          uni.$emit("loaded", p);
        },
      });
    },
  });
  return { app };
}
